#pragma once

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include "type.h"

// char stream -> token

enum class TokenType
{
    unknown,    // 未知
    number,     // [0-9]+
    indentifier,// 变量
    kw_int,     // int
    plus,       // +
    minus,      // -
    star,       // *
    slash,      // /
    equal,      // =
    l_parent,   // (
    r_parent,   // )
    semi,       // ;
    comma,      // ,
    eof         // end of file
};

class Token
{
public:
    Token()
    {
        row = col = -1;
        tokenType = TokenType::unknown;
        value = -1;
    }
    void Dump();
public:
    int row, col;
    TokenType tokenType; // token 的种类
    int value;
    llvm::StringRef content;
    CType *type;
};

class Lexer
{
public:
    Lexer(llvm::StringRef sourceCode);
    void NextToken(Token& token);
public:
    const char * BufPtr;
    const char * LineHeadPtr;
    const char * BufEnd;
    // Token token; // 冗余的，NextToken 内传参本身用的就是引用，这里的token也就没有存在的意义了
    int row;
};